package com.whmskj.xjlhsc.stationmachine.service.imp;

import com.whmskj.xjlhsc.stationmachine.mapper.StationmachineEnergyConsumptionMapper;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.EnergyConsumptionVO;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.EnergyProcessVO;
import com.whmskj.xjlhsc.stationmachine.pojo.vo.EnergyTimeVO;
import com.whmskj.xjlhsc.stationmachine.service.IStationmachineEnergyConsumptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jiaruchun
 * @date 2025-09-18 10:45
 */
@Service
public class StationmachineEnergyConsumptionServiceImpl implements IStationmachineEnergyConsumptionService {
    @Autowired
    private StationmachineEnergyConsumptionMapper energyConsumptionMapper;

    @Override
    public EnergyConsumptionVO getEnergyConsumption() {
        EnergyConsumptionVO energyConsumptionVO = new EnergyConsumptionVO();
        //日--
        List<EnergyProcessVO> energyConsumptionProcessDay = energyConsumptionMapper.getEnergyConsumptionProcessDay();
        energyConsumptionVO.setEnergyProcessListDay(energyConsumptionProcessDay);
        List<EnergyTimeVO> timeListDay = energyConsumptionMapper.getTimeListDay();
        if (timeListDay != null && !timeListDay.isEmpty()) {
            energyConsumptionVO.setDay(timeListDay.get(timeListDay.size() - 1).getEnergy());
        }else {
            energyConsumptionVO.setDay(0F);
        }
        energyConsumptionVO.setTimeListDay(timeListDay);
        //月-----
        List<EnergyProcessVO> energyConsumptionProcessMonth = energyConsumptionMapper.getEnergyConsumptionProcessMonth();
        energyConsumptionVO.setEnergyProcessListMonth(energyConsumptionProcessMonth);
        List<EnergyTimeVO> timeListMonth = energyConsumptionMapper.getTimeListMonth();
        if (timeListMonth != null && !timeListMonth.isEmpty()) {
            energyConsumptionVO.setMonth(timeListMonth.get(timeListMonth.size() - 1).getEnergy());
        }else {
            energyConsumptionVO.setMonth(0F);
        }
        energyConsumptionVO.setTimeListMonth(timeListMonth);
        //年-----
        List<EnergyProcessVO> energyConsumptionProcessYear = energyConsumptionMapper.getEnergyConsumptionProcessYear();
        energyConsumptionVO.setEnergyProcessListYear(energyConsumptionProcessYear);
        List<EnergyTimeVO> timeListYear = energyConsumptionMapper.getTimeListYear();
        if (timeListYear != null && !timeListYear.isEmpty()) {
            energyConsumptionVO.setYear(timeListYear.get(timeListYear.size() - 1).getEnergy());
        }else {
            energyConsumptionVO.setYear(0F);
        }
        energyConsumptionVO.setTimeListYear(timeListYear);
        return energyConsumptionVO;
    }
}
